<template>
  <div class="app-container">
    <div class="filter-container">
      <el-input v-model="listQuery.productCode" placeholder="产品编号" style="width: 100px;" class="filter-item" @keyup.enter.native="handleFilter" />
      <el-input v-model="listQuery.workpieceCode" placeholder="工件编号" style="width: 150px;" class="filter-item" @keyup.enter.native="handleFilter" />
      <el-input v-model="listQuery.workpieceName" placeholder="工件名字" style="width: 150px;" class="filter-item" @keyup.enter.native="handleFilter" />
      <el-input v-model="listQuery.month" placeholder="完成月份" style="width: 100px;" class="filter-item" @keyup.enter.native="handleFilter" />

      <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">
        搜索
      </el-button>
    </div>
    <el-table
      v-loading="listLoading"
      :data="list"
      element-loading-text="Loading"
      height="600"
      border
      style="width: 100%">
      <el-table-column type="index" align="center" fixed> </el-table-column>

      <el-table-column label="产品" align="center" width="220" fixed>
        <el-table-column label="产品新编码" align="center" prop="productCode" width="120">
          <template slot-scope="scope">
            {{ scope.row.productCode }}
          </template>
        </el-table-column>
        <el-table-column label="产品老编码" align="center" prop="oldCode" width="100"></el-table-column>
      </el-table-column>

      <el-table-column label="工件" align="center" width="320" fixed>
        <el-table-column label="工件名称" align="center" prop="workpieceName" width="100">
          <template slot-scope="scope">
            {{ scope.row.workpieceName }}
          </template>
        </el-table-column>
        <el-table-column label="工件编码" align="center" prop="workpieceCode" width="120">
          <template slot-scope="scope">
            {{ scope.row.workpieceCode }}
          </template>
        </el-table-column>
        <el-table-column label="总月计划数" align="center" prop="mouthCount" width="100">
        </el-table-column>
      </el-table-column>

      <!--  每个工序 31天    -->
      <el-table-column label="工序" >
        <el-table-column label="工序-1">
          <el-table-column v-for="(item, index) in 31" :label="index+1" >
            <template slot-scope="scope">
              {{ scope.row.procedureMap[1].mouthCountMap[index+1] }}
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="工序-2">
          <el-table-column v-for="(item, index) in 31" :label="index+1" >
            <template slot-scope="scope">
              {{ scope.row.procedureMap[2].mouthCountMap[index+1] }}
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="工序-3">
          <el-table-column v-for="(item, index) in 31" :label="index+1" >
            <template slot-scope="scope">
              {{ scope.row.procedureMap[3].mouthCountMap[index+1] }}
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column label="工序-4">
          <el-table-column v-for="(item, index) in 31" :label="index+1" >
            <template slot-scope="scope">
              {{ scope.row.procedureMap[4].mouthCountMap[index+1] }}
            </template>
          </el-table-column>
        </el-table-column>
      </el-table-column>

    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />

  </div>
</template>

<script>
import { fetchList } from '@/api/workpiece'
import Pagination from '@/components/Pagination'

export default {
  components: { Pagination },
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'gray',
        deleted: 'danger'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      list: null,
      listLoading: true,
      total: 0,
      listQuery: {
        page: 1,
        limit: 10,
        month: '2019-10',
        productCode: undefined,
        workpieceCode: undefined,
        workpieceName: undefined
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      this.listLoading = true
      fetchList(this.listQuery).then(response => {
        this.list = response.data.items
        this.total = response.data.total

        // Just to simulate the time of the request
        setTimeout(() => {
          this.listLoading = false
        }, 1.5 * 1000)
      })
    },
    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    }
  }
}
</script>
